<template>
  <div>
    <el-form :model="loginForm" :rules="rules2" ref="loginForm" label-position="left" label-width="0px" class="demo-ruleForm login-container">
      <h3 class="title">系统登录</h3>
      <el-form-item prop="account">
        <el-input type="text" v-model="loginForm.username" auto-complete="off" placeholder="账号"></el-input>
      </el-form-item>
      <el-form-item prop="checkPass">
        <el-input type="password" v-model="loginForm.password" auto-complete="off" placeholder="密码"></el-input>
      </el-form-item>
      <el-form-item style="width:100%;">
        <el-button type="primary" style="width:47%;" @click.native.prevent="handleSubmit">登录</el-button>
        <el-button type="danger" style="width:47%;" @click.native.prevent="handleSettled">商家入驻</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import { requestLogin } from '../api/api';
  //import NProgress from 'nprogress'
  export default {
    data() {
      return {
        rules2: {
          username: [
            { required: true, message: '请输入账号', trigger: 'blur' },
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
          ]
        },
        checked: true,
        loginForm:{
          username:"admin",
          password:"123456"
        }
      };
    },
    methods: {
      handleSettled(){
        this.$router.push("/shopRegister")
      },
      handleSubmit() {
        this.$refs.loginForm.validate((valid) => {
          if (valid) {
            console.log(this.loginForm)
            this.$http.post("login",this.loginForm)
            .then(result => {
              result = result.data
              if (result.success) {
                this.$message({ message: "登录成功",type: 'success'});
                localStorage.setItem("token",result.data)
                this.$router.push("/echarts")
              } else {
                this.$message({ message: result.message,type: 'error'});
              }
            })
            .catch(() =>{
              this.$message({ message: "网络异常！",type: 'error'});
            })
          }
        });
      }
    }
  }

</script>

<style lang="scss" scoped>
  .login-container {
    /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    .title {
      margin: 0px auto 40px auto;
      text-align: center;
      color: #505458;
    }
    .remember {
      margin: 0px 0px 35px 0px;
    }
  }
</style>